package problema022;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Collections;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class NameScores {

	static LinkedList <String> lista;
	
	public static void main(String[] args){
		System.out.println(sumaNombres());
	}
	
	public static long sumaNombres(){
		leer();
		Collections.sort(lista);
		long res = 0;
		long act = 0;
		for(int i = 0; i < lista.size(); i++){
			for(int j = 0; j < lista.get(i).length(); j++){
				act += lista.get(i).charAt(j) - 64;
			}
			res += (i+1) * act;
			act = 0;
		}
		return res;
	}
	
	public static void leer(){
		lista = new LinkedList<String>();
		String nombre;
		try{
			BufferedReader reader = new BufferedReader( new FileReader("nombresEj22.txt") );
			String linea;
			while ((linea = reader.readLine()) != null){
				StringTokenizer st = new StringTokenizer(linea, "," );
				while (st.hasMoreTokens()){
					nombre = st.nextToken();
					lista.add(nombre.substring(1, nombre.length()-1));
				}
			}
			reader.close();
			}catch (Exception e){
				System.err.println("Error: " + e.getMessage());
			}
	}

}
